package com.xhj.ipersistent.session;

import com.xhj.ipersistent.builder.XMLConfigurationBuilder;
import com.xhj.ipersistent.config.Configuration;
import org.dom4j.DocumentException;

import java.io.InputStream;

/**
 * SqlSessionFactoryBuilder
 *
 * @author XJks
 * @description SqlSessionFactory的建造者，通过解析配置文件，创建SqlSessionFactory
 */
public class SqlSessionFactoryBuilder {

    public SqlSessionFactoryBuilder() {
    }

    public SqlSessionFactory build(InputStream inputStream) throws DocumentException {
        // 使用XMLConfigurationBuilder专门解析核心配置文件
        XMLConfigurationBuilder xmlConfigurationBuilder = new XMLConfigurationBuilder();
        Configuration configuration = xmlConfigurationBuilder.parse(inputStream);
        // 创建SqlSessionFactory工厂对象
        return new DefaultSqlSessionFactory(configuration);
    }
}
